package com.ruoyi.web.controller.shopping;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.system.domain.shopping.Area;
import com.ruoyi.system.domain.shopping.Category;
import com.ruoyi.system.domain.shopping.Product;
import com.ruoyi.system.domain.shopping.dto.ProductVoDto;
import com.ruoyi.system.domain.shopping.vo.ProductVo;
import com.ruoyi.system.service.shopping.AreaService;
import com.ruoyi.system.service.shopping.ProductService;
import com.ruoyi.system.view.common.Result;
import com.ruoyi.system.view.common.ResultList;
import com.ruoyi.web.controller.shopping.common.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/xiaomi/v2/product")
public class ProductController {

    @Autowired
    private ProductService productService;


    @GetMapping
    public ResultList<List<ProductVo>> list(@RequestParam(required = true) Integer pageNum,
                                            @RequestParam(required = true) Integer pageSize,
                                            Product product){
        PageHelper.startPage(pageNum, pageSize);
        List<ProductVo> productVos = productService.selectProductVoList(product);
        PageInfo<ProductVo> pageInfo = new PageInfo<>(productVos);
        return ResultList.success(pageInfo.getList(),(int) pageInfo.getTotal(),"查询成功");
    }

    @GetMapping("/hot")
    public ResultList<List<Category>> hotList(){
        List<Category> categories = productService.selectProductHostList();
        return ResultList.success(categories,Integer.valueOf(categories.size()),"查询成功");
    }

    @GetMapping("/{productId}")
    public Result<ProductVoDto> infoById(@PathVariable Integer productId){
        ProductVoDto productVoDto = productService.selectProductVoDtoByproductId(productId,BaseContext.getId());
        return Result.success(productVoDto,"查询成功");
    }
}
